package com.exam.scjp5.objectives.section_1;

public class ExampleFinalVariable
{
    public static void main(String args[])
    {
        // For FINAL1 : Compiler is sure that 'if' condition will always be true.
        // Because of 'if(true)', the complier is sure that 'FINAL1=10' expression
        // will be executed surely.
        final int FINAL1;        
        if(true)
            FINAL1 = 10;
        System.out.println("FINAL1 : " + FINAL1);
        
        
        // For FINAL2: Compiler is sure that 'finally' clause will be executed after 'try'.
        final int FINAL2;
        try
        {
            
        }
        finally
        {
            FINAL2 = 0;
        }
        System.out.println("FINAL2 : " + FINAL2);
        
        
        // ERROR!!! Here compiler can't be sure everTrue() will return 'true' forever or not.
        final int FINAL3;
        if(everTrue())
            FINAL3 = 10;
        System.out.println("FINAL3 : " + FINAL3); // ERROR!!
        
        // ERROR!!! Here compiler also can't be sure 'b' will be true forever or not.
        final int FINAL4;
        boolean b = true;
        if(b)
            FINAL4 = 10;
        System.out.println("FINAL4 : " + FINAL4); // ERROR!!
        
    }
    
    public static boolean everTrue()
    {
        return true;
    }
}
